layui.use(['layer', 'form', 'table', 'ztree', 'laydate', 'admin', 'ax'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var laydate = layui.laydate;
    var admin = layui.admin;

    /**
     * 系统管理--用户管理
     */
    var exam = {
        tableId: "examTable",    //表格id
        condition: {
            name: "",
            deptId: "",
            timeLimit: ""
        }
    };

    /**
     * 初始化表格的列
     */
    exam.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'exam_id', hide: true, sort: true, title: 'exam_id'},
            {field: 'school_user_id', hide: true, sort: true, title: 'school_user_id'},
            {field: 'school_name', sort: true, title: '学校名称'},
            {field: 'exam_title', sort: true, title: '考试名称'},
            {field: 'students', sort: true, title: '共缴费人数'},
            {field: 'examstudents', sort: true, title: '未缴费人数' ,templet: function (d) {
                    return d.students - d.examstudents;
             }},
            {field: 'exam_place_cost', sort: true, title: '考点费'},
            {field: 'zt', sort: true, title: '状态',templet: function (d) {
                    var zt = "";
                    if((d.students - d.examstudents)== 0){
                        zt = "已全交";
                    }else {
                        zt = "未交齐";
                    }
                    if(exam_content){
                        var exam_content = JSON.parse(d.exam_content)
                        for (var i = 0; i < exam_content.length; i++) {
                            if(new Date(exam_content[i].examTime)<new Date()){
                                zt +=",已过期";
                            }
                        }
                    }
                    return zt;
             }},
            {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 150}
        ]];
    };

    /**
     * 点击查询按钮
     */
    exam.search = function () {
        var queryData = {};
        queryData['name'] = $("#name").val();
        table.reload(exam.tableId, {where: queryData});
    };

    /**
     * 导出excel按钮
     */
    exam.exportExcel = function () {
        var checkRows = table.checkStatus(exam.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    /**
     * 点击编辑用户按钮时
     *
     * @param data 点击按钮时候的行数据
     */
    exam.onViewExam = function (data) {
        admin.putTempData('formOk', false);
        layer.full(layui.admin.open({
            type: 2,
            title: '查看',
            area: ['100%', '100%'],
            content: Feng.ctxPath + '/exam/paymentRecord_view',
            end: function () {
                admin.getTempData('formOk') && table.reload(exam.tableId);
            }
        }));
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + exam.tableId,
        url: Feng.ctxPath + '/exam/paymentRecordList',
        page: true,
        height: "full-98",
        cellMinWidth: 120,
        cols: exam.initColumn()
    });


    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        exam.search();
    });

    // 导出excel
    $('#btnExp').click(function () {
        exam.exportExcel();
    });

    // 工具条点击事件
    table.on('tool(' + exam.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'view') {
            exam.onViewExam(data);
        }
    });

});
